import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:series_play/comm/base/app_controller.dart';
import 'package:series_play/route/route_path.dart';

/// 登录中间件
class LoginMiddleware extends GetMiddleware {

  @override
  int? get priority => 1;

  @override
  RouteSettings? redirect(String? route) {
    bool isLogin = Get.find<AppController>().isLogin;

    // 未登录且目标页不是登录页，则重定向到登录页
    if (!isLogin && route != RoutePath.quickLogin) {
      return const RouteSettings(name: RoutePath.quickLogin);
    }

    return null;
  }
}
